<template>
  <cfg-form :ref="ref" v-bind="attrs" :data="data.values"></cfg-form>
</template>

<script>
import { typeClassName } from "@/pages/config/classNameMap";
export default {
  name: "pg-form",
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref: "createView",
      onlyRead: false,
      loading: false,
      jobOptions: [],
      positionOptions: [],
      educationOptions: [
        { label: "初中及以下", value: "初中及以下" },
        { label: "高中/中专", value: "高中/中专" },
        { label: "大专", value: "大专" },
        { label: "本科", value: "本科" },
        { label: "硕士", value: "硕士" },
        { label: "博士", value: "博士" },
      ],
      genderOptions: [
        { label: "男", value: "男" },
        { label: "女", value: "女" },
      ],
      statusOptions: [
        { label: "在职", value: "在职" },
        { label: "离职", value: "离职" },
      ],

      jobClassObject: {},
      positionClassObject: {},
    };
  },
  props: {
    data: {
      default: () => {
        return {};
      },
    },
  },
  watch: {},
  computed: {
    attrs() {
      return {
        labelWidth: 100,
        labelPosition: "right",
        cols: 2,
        columns: [
          {
            key: "sf_code",
            title: "人员编码",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "sf_name",
            title: "人员姓名",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "idType",
            title: "证件类型",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "sf_idNumber",
            title: "证件号码",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "status",
            title: "状态",
            minWidth: 70,
            align: "center",
            config: { type: "radio", options: this.statusOptions },
          },
          {
            key: "majorCode",
            title: "主岗名称",
            minWidth: 100,
            align: "center",
            config: { type: "select", options: this.jobOptions },
          },
          {
            key: "jobCode",
            title: "所属岗位名称",
            minWidth: 100,
            align: "center",
            config: { type: "select", options: this.jobOptions },
          },
          {
            key: "age",
            title: "年龄",
            minWidth: 70,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "gender",
            title: "性别",
            minWidth: 70,
            align: "center",
            config: { type: "radio", options: this.genderOptions },
          },
          {
            key: "positionName",
            title: "职级名称",
            minWidth: 100,
            align: "center",
            config: { type: "select", options: this.positionOptions },
          },
          {
            key: "natural",
            title: "资质",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "field",
            title: "专业",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "email",
            title: "电子邮件",
            minWidth: 100,
            align: "center",
            config: { type: "text" },
          },
          {
            key: "phone",
            title: "手机号码",
            minWidth: 100,
            align: "center",
            config: { type: "number" },
          },
          {
            key: "startworkdate",
            title: "入职日期",
            minWidth: 100,
            align: "center",
            config: { type: "date" },
          },
          {
            key: "education",
            title: "学历",
            minWidth: 100,
            align: "center",
            config: { type: "select", options: this.educationOptions },
          },
          // {
          //   key: "directLeaderName",
          //   title: "直属领导",
          //   minWidth: 100,
          //   align: "center",
          //   config: { type: "link", link: this.selectDirectLeader },
          // },
          // {
          //   key: "acrossLeaderName",
          //   title: "隔级领导",
          //   minWidth: 100,
          //   align: "center",
          //   config: { type: "link", link: this.selectAccessLeader },
          // },
          {
            key: "isSafetyCertificate",
            title: "是否具备安全资格证",
            minWidth: 100,
            align: "center",
            config: {
              type: "radio",
              options: [
                { label: "是", value: "是" },
                { label: "否", value: "否" },
              ],
            },
          },
          {
            key: "safeStartTime",
            title: "安全资格证开始时间",
            minWidth: 100,
            align: "center",
            config: { type: "date" },
          },
          {
            key: "safeValidity",
            title: "安全资格证有效期",
            minWidth: 100,
            align: "center",
            config: { type: "number" },
          },
          {
            key: "isSpecialCertificate",
            title: "是否具备特种作业资格证",
            minWidth: 100,
            align: "center",
            config: {
              type: "radio",
              options: [
                { label: "是", value: "是" },
                { label: "否", value: "否" },
              ],
            },
          },
          {
            key: "SpecialStartTime",
            title: "特种作业证开始时间",
            minWidth: 100,
            align: "center",
            config: { type: "date" },
          },
          {
            key: "specialValidity",
            title: "特种作业证有效期",
            minWidth: 100,
            align: "center",
            config: { type: "number" },
          },
          {
            key: "remark",
            title: "备注",
            minWidth: 100,
            align: "center",
            config: { type: "textarea" },
          },
        ],
        rules: {
          sf_code: [
            { required: true, message: "不能为空", trigger: "blur" },
            { max: 50, message: "编码长度不能超过50", trigger: "blur" },
          ],
          sf_name: [
            { required: true, message: "不能为空", trigger: "blur" },
            { max: 200, message: "姓名长度不能超过200", trigger: "blur" },
          ],
          gender: [{ required: true, message: "不能为空", trigger: "change" }],
          // jobCode: [{ required: true, message: "不能为空", trigger: "change" }],
          status: [{ required: true, message: "不能为空", trigger: "change" }],
          email: [
            { type: "email", message: "请输入正确的邮箱地址", trigger: "blur" },
          ],
          // sf_idNumber: [
          //   { max: 200, message: '身份证号不能超过200', trigger: 'blur'},
          //   { pattern: /(^\d{15})|(\d18)|(\d18)|(^\d{17}(\d|X|x)$)/, message: '请输入合法的身份证号', trigger: 'blur'}
          // ],
          remark: [
            { max: 500, message: "请不要超出500个字符", trigger: "blur" },
          ],
        },
        // onlyRead: this.onlyRead,
      };
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      this.jobClassObject = this.$modelObject.create(
        `${typeClassName["job"].modelType}`
      );
      this.positionClassObject = this.$modelObject.create(
        `${typeClassName["position"].modelType}`
      );
      this.anc.setOptionsByHier(
        "job",
        this.jobClassObject,
        "jobOptions",
        {
          label: "sf_name",
          value: "sf_code",
        },
        "createView"
      );
      this.anc.setOptionsByHier(
        "position",
        this.positionClassObject,
        "positionOptions",
        {
          label: "sf_name",
          value: "sf_code",
        },
        "createView"
      );
    });
  },
  methods: {
    validate(fn) {
      return this.$refs[this.ref].$refs["form"].validate((valid) => {
        if (fn) {
          return fn(valid);
        } else {
          return valid;
        }
      });
    },
    resetFields() {
      this.$refs[this.ref].$refs["form"].resetFields();
    },
  },
};
</script>
<style scoped></style>
